# -*- coding: utf-8 -*-
# ----------------------------
# @Time    : 2021/7/4 4:26 下午
# @Author  : changqingai
# @FileName: 04-accumulator.py
# ----------------------------

from pyspark import SparkContext

if __name__ == "__main__":
    sc = SparkContext(master='local[2]', appName='accumulator')
    num = sc.accumulator(10)
    def f(x):
        global num
        num += x
    rdd = sc.parallelize([20, 30, 40, 50])
    rdd.foreach(f)
    print('num:', num)
